//
//  bigHeadImageDataSource.m
//  tcpoctest
//
//  Created by gump on 4/20/13.
//  Copyright (c) 2013 gump. All rights reserved.
//

#import "bigHeadImageDataSource.h"
#import "sendHeadImageBig.h"
#import "BigImageInfo.h"

@implementation bigHeadImageDataSource

-(id)init
{
    self = [super init];
    if(self)
    {
        iImage = [[UIImage alloc] init];
        self.UserBigImage = nil;
        self.bigimageDic = [[NSMutableDictionary alloc] init];
        
        self.bigimageRequestSet = [[NSMutableSet alloc] init];
        bigimageSendArr = [[NSMutableArray alloc] init];
        
        pthread_mutex_init(&mutexBigHI, 0);
    }
    
    return self;
}

-(BigImageInfo *)SearchBigImageByMail:(NSString *)strmail
{
    BigImageInfo *strurl = nil;
    
    if (strmail == nil) {
        return nil;
    }
    
    pthread_mutex_lock(&mutexBigHI);
    
    strurl = [self.bigimageDic objectForKey:strmail];
    
    if (strurl == nil) {
        
        if (![self.bigimageRequestSet containsObject:strmail]) {
            [self.bigimageRequestSet addObject:strmail];
            [bigimageSendArr addObject:strmail];
            
            [[DataControl shareControl].LCDS addLogicCommand:LC_BIGIMAGE_SEARCH];
        }
        
    }
    
    pthread_mutex_unlock(&mutexBigHI);
    
    return strurl;
}

-(void)SetUserBigImage:(UIImage *)BigImage
{
    self.UserBigImage = BigImage;
}

-(void)SendBigImageRequest
{
    pthread_mutex_lock(&mutexBigHI);
    
    for (NSString *strmail in bigimageSendArr) {
        
        [[netManager sharedNetManager].sendHIBig sendReadBigHeadImageP:strmail];
        
        
    }
    
    [bigimageSendArr removeAllObjects];
    
    pthread_mutex_unlock(&mutexBigHI);
}

@end
